package com.yatuhashi.manual.mhp3.custom;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.yatuhashi.manual.mhp3.R;


public class BaseGridAdapter extends ArrayAdapter<Object> {
    Resources res;
    LayoutInflater inflater;
    
    public BaseGridAdapter(Context context) {
        super(context, 0);
        res = context.getResources();
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder;
        Bitmap bmp = (Bitmap) getItem(position);
       
        if(convertView==null) {
            mHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.row_grid, null);
            mHolder.gridImage = (ImageView) convertView.findViewById(R.id.grid_image);
            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }
        if(bmp!=null) {
            mHolder.gridImage.setImageBitmap(bmp);
        }
        return convertView;
    }
}
